package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.ProblemerMapper;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Order;
import com.cn.crmsystem.pojo.Problem;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProblemerServiceImpl implements ProblemService {
    @Autowired
    private ProblemerMapper problemerMapper;

    public ResultJson selectProblemAll(Map map) {
        List<Problem> selectProblemAll = problemerMapper.selectProblemAll(map);
        ResultJson resultJson = new ResultJson();
        if (selectProblemAll != null) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson selectProblemById(Integer id) {
        Order selectProblemById = problemerMapper.selectProblemById(id);
        ResultJson resultJson = new ResultJson();
        if (selectProblemById != null) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;

    }

    @Override
    public ResultJson addProblem(Problem problem,Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("problem",problem);
        map.put("login",login);
        Order addProblem = problemerMapper.addProblem(map);
        ResultJson resultJson = new ResultJson();
        if (addProblem != null) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;

    }

    @Override
    public ResultJson updateProblem(Integer id) {

        int updateProblem = problemerMapper.updateProblem(id);
        ResultJson resultJson = new ResultJson();
        if (updateProblem >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;
    }

    @Override
    public ResultJson deleteByIdProblem(Integer id) {
        int deleteByIdProblem = problemerMapper.deleteByIdProblem(id);
        ResultJson resultJson = new ResultJson();
        if (deleteByIdProblem>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }
}
